package com.yanwq.pulltorefreshview.view;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.view.View;

/**
 * 作者：yanweiqiang。
 * 日期：2016/5/12 0012。
 */
public class PullToActionUtil {
    private View rootView;

    public PullToActionUtil(View rootView) {
        super();
        this.rootView = rootView;
    }

    public void resizeHeaderHeight(int height) {
        rootView.getLayoutParams().height = height;
        rootView.requestLayout();
    }

    public void animHeaderHeight(int from, int to) {
        animHeaderHeight(from, to, null);
    }

    public void animHeaderHeight(int from, int to, Animator.AnimatorListener listener) {
        ValueAnimator animator = new ValueAnimator();
        animator.cancel();
        animator.setIntValues(from, to);
        animator.setDuration(200);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int value = (int) animation.getAnimatedValue();
                resizeHeaderHeight(value);
            }
        });

        if (listener != null) {
            animator.addListener(listener);
        }

        animator.start();
    }
}
